package com.myplans.shared;

public class FacebookUtil {
    private static final String API_KEY = "294163280657375";
    private static final String SECRET = "d362b51f96d81b45991f70c4acda5a2b"; 
    public static final String APPLICATION_ID = "294163280657375 "; 
 
    private static final String FB_GRAPH_URL = "https://graph.facebook.com/";
    private static final String FB_OAUTH_URL = FB_GRAPH_URL + "oauth/";
    private static final String FB_FRIENDS_URL = FB_GRAPH_URL + "me/friends?";
    private static final String FB_ME_URL = FB_GRAPH_URL + "me?fields=picture,name,username,email&access_token=";
    private static final String FEED_URL = FB_GRAPH_URL + "me/feed?access_token=";

    // localhost is for testing
    private static final String REDIRECT_URL = "http://127.0.0.1:8080/web";
 
    public static String getApplicationId() {
        return APPLICATION_ID;
    }
 
    public static String getAPIKey() {
        return API_KEY;
    }
 
    public static String getSecret() {
        return SECRET;
    }
 
    public static String getAuthorizeUrl() {
        final StringBuilder sb = new StringBuilder(FB_OAUTH_URL);
        sb.append("authorize?type=user_agent&client_id=").append(APPLICATION_ID);
        sb.append("&display=page&redirect_uri=").append(REDIRECT_URL);
        sb.append("&scope=user_status,publish_stream,offline_access,email");
        return sb.toString();
    }
    
    public static String getPublishFeedUrl(String authToken, Plan plan) {
    	final StringBuilder sb = new StringBuilder(FEED_URL);
    	sb.append(authToken);
    	sb.append("&message=Check this plan: ");
    	sb.append("&name=" + plan.getName());
    	sb.append("&description=" + plan.getDate().toString() + " " + plan.getDescription());
    	sb.append("&link=" + REDIRECT_URL);
    	
    	return sb.toString();
    }
 
    public static String getAccessTokenUrl(final String authCode) {
        final StringBuilder sb = new StringBuilder(FB_OAUTH_URL);
        sb.append("access_token?client_id=").append(
                APPLICATION_ID);
        sb.append("&redirect_uri=").append(REDIRECT_URL);
        sb.append("&client_secret=").append(SECRET);
        sb.append("&code=").append(authCode);
        return sb.toString();
    }
    
    public static String getPictureUrl(final Long id) {
    	final StringBuilder sb = new StringBuilder(FB_GRAPH_URL);
    	sb.append(id + "/picture?type=large");
    	return sb.toString();
    }
 
    public static String getFriendsUrl(final String authToken) {
        return FB_FRIENDS_URL + authToken;
    }
    
    public static String getMeUrl(final String authToken){
        return FB_ME_URL + authToken;
    }
    
}
